package com.macasa.panel.dao.hibernate.api;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.macasa.panel.entity.api.IModel;
import com.macasa.panel.exception.DAOException;

/**
 * Interface IGenericDAO
 * <P>
 * 
 * @author Mickaël Husson
 * @date 01/01/2012
 */
public interface IDao<DTO extends IModel<ID>, ID extends Serializable> extends Serializable {

	/**
	 * Creates the or update.
	 * 
	 * @param dto
	 *            the dto
	 * @throws DAOException
	 *             the DAO exception
	 */
	void createOrUpdate(final DTO dto) throws DAOException;

	/**
	 * Delete.
	 * 
	 * @param dto
	 *            the dto
	 * @throws DAOException
	 *             the DAO exception
	 */
	void delete(final DTO dto) throws DAOException;

	/**
	 * Evict.
	 * 
	 * @param dto
	 *            the dto
	 * @throws DAOException
	 *             the DAO exception
	 */
	void evict(final DTO dto) throws DAOException;

	/**
	 * Flush.
	 * 
	 * @throws DAOException
	 *             the DAO exception
	 */
	void flush() throws DAOException;

	/**
	 * Gets the all id.
	 * 
	 * @return the all id
	 * @throws DAOException
	 *             the DAO exception
	 */
	List<ID> getAllId() throws DAOException;

	/**
	 * Gets the hibernate session.
	 * 
	 * @return the hibernate session
	 * @throws DAOException
	 *             the DAO exception
	 */
	Session getHibernateSession() throws DAOException;

	/**
	 * Gets the find all number.
	 * 
	 * @return the find all number
	 * @throws DAOException
	 *             the DAO exception
	 */
	Integer getfindAllNumber() throws DAOException;

	/**
	 * find all.
	 * 
	 * @return the list<DTO>
	 * @throws DAOException
	 *             the DAO exception
	 */
	List<DTO> findAll() throws DAOException;

	/**
	 * find all.
	 * 
	 * @param firstResult
	 *            the first result
	 * @param maxResults
	 *            the max results
	 * @return the list<DTO>
	 * @throws DAOException
	 *             the DAO exception
	 */
	List<DTO> findAll(final int firstResult, final int maxResults) throws DAOException;

	/**
	 * find by criteria.
	 * 
	 * @param criteria
	 *            the criteria
	 * @return the list<DTO>
	 * @throws DAOException
	 *             the DAO exception
	 */
	List<DTO> findByCriteria(final Criteria criteria) throws DAOException;

	/**
	 * find by id.
	 * 
	 * @param id
	 *            the id
	 * @return the DTO
	 * @throws DAOException
	 *             the DAO exception
	 */
	DTO findById(final ID id) throws DAOException;

	/**
	 * find by ids.
	 * 
	 * @param ids
	 *            the List of id
	 * @return the list<DTO>
	 * @throws DAOException
	 *             the DAO exception
	 */
	List<DTO> findByIds(final List<ID> ids) throws DAOException;

	/**
	 * find by query.
	 * 
	 * @param query
	 * @param paramValues
	 * @return the list<DTO>
	 * @throws DAOException
	 *             the DAO exception
	 */
	List<DTO> findByQuery(final String query, final Object[] paramValues) throws DAOException;

	/**
	 * find by attribute
	 * 
	 * @param attributeName
	 *            Attribute to search
	 * @param value
	 *            Value of the attribute
	 * 
	 * @return the list<DTO>
	 * @throws DAOException
	 *             the DAO exception
	 */
	List<DTO> findByAttribute(final String attributeName, final Object value) throws DAOException;

	/**
	 * find by unique attribute
	 * 
	 * @param attributeName
	 *            Attribute to search
	 * @param value
	 *            Value of the attribute
	 * 
	 * @return the DTO
	 * @throws DAOException
	 *             the DAO exception
	 */
	DTO findByUniqueAttribute(final String attributeName, final Object value) throws DAOException;

	/**
	 * find by attribute
	 * 
	 * @param attributeName
	 *            Attribute to search
	 * @param values
	 *            List of value for the attribute
	 * 
	 * @return the list<DTO>
	 * @throws DAOException
	 *             the DAO exception
	 */
	List<DTO> findByAttributes(final String attributeName, final List<? extends Object> values) throws DAOException;

	/**
	 * @return the sessionFactory
	 */
	SessionFactory getSessionFactory();

	/**
	 * @param sessionFactory
	 *            the sessionFactory to set
	 */
	void setSessionFactory(final SessionFactory sessionFactory);
}
